<?php
	defined('INDEX') or die ('Acesso direto n&atilde;o permitido');
	    
	/**
	 * This is a main class for manage the object instance for all 
	 * application.
	 * 
	 * @author Carlos A. Junior
	 */
	class ApplicationFactory
	{
		/**
		 * Static object of SessionManager.
		 * 
		 * @var SessionManager
		 */
		static private $session = null;
		
		/**
		 * Static object of Configutation.
		 * 
		 * @var Configutation
		 */
		static private $config	= null;
		
		/**
		 * Static object of Request.
		 * 
		 * @var Request
		 */
		static private $request	= null;
		
		/**
		 * Static object of Parser.
		 * 
		 * @var Parser
		 */
		static private $parser	= null;
		
		/**
		 * Static object of DoctrineConnection.
		 * 
		 * @var DoctrineConnection
		 */
		static private $connection	= null;
		
		/**
		 * Static object of DoctrineModelGenerator.
		 * 
		 * @var DoctrineModelGenerator
		 */
		static private $doctrineModelGenerator	= null;
		
		/**
		 * Static object of PageAccessControl.
		 * 
		 * @var PageAccessControl
		 */
		static private $pageAccessControl	= null;
		
		/**
		 * Static object of Debug.
		 * 
		 * @var Debug
		 */
		static private $debug	= null;
		
		/**
		 * Static object of CapabilityManager.
		 * 
		 * @var CapabilityManager
		 */
		static private $capabilityManager = null;
		
		/**
		 * Static object of HTMLComponent.
		 * 
		 * @var HTMLComponent
		 */
		static private $htmlComponent = null;
		
		/**
		 * Returns an instance of SessionManager object. If instance
		 * is null create a new instance.
		 * 
		 * @return SessionManager $session
		 */
		public static function getSessionFactory ()
		{
			if(self::$session == null)
			{
				require_once (dirname(__FILE__)."/../session/SessionManager.class.php");
				self::$session = new SessionManager();
			}
			
			return self::$session;
		}
		
		/**
		 * Returns an instance of Configuration object. If instance
		 * is null create a new instance.
		 * 
		 * @return Configuration $session
		 */
		public static function getConfigurationFactory ()
		{
			if(self::$config == null)
			{
				require_once (dirname(__FILE__)."/Configuration.class.php");
				self::$config = new Configuration();
			}
			
			return self::$config;
		}
		
		/**
		 * Returns an instance of Request object. If instance
		 * is null create a new instance.
		 * 
		 * @return Request $request
		 */
		public static function getRequestFactory ()
		{
			if(self::$request == null)
			{
				require_once (dirname(__FILE__)."/../request/Request.class.php");
				self::$request = new Request();
			}
			
			return self::$request;
		}
		
		/**
		 * Returns an instance of Parser object. If instance
		 * is null create a new instance.
		 * 
		 * @return Parser $parser
		 */
		public static function getParserFactory ()
		{
			if(self::$parser == null)
			{
				require_once (dirname(__FILE__)."/Parser.class.php");
				self::$parser = new Parser();
			}
			
			return self::$parser;
		}
		
		/**
		 * Returns an instance of Connection object. If instance
		 * is null create a new instance.
		 * 
		 * @return DoctrineConnection $connection
		 */
		public static function getDoctrineConnectionFactory ()
		{
			if(self::$connection == null)
			{
				require_once (dirname(__FILE__)."/../doctrine/DoctrineConnection.class.php");
				self::$connection = new DoctrineConnection();
			}
			
			return self::$connection;
		}
		
		/**
		 * Returns an instance of DoctrineModelGenerator object. If instance
		 * is null create a new instance.
		 * 
		 * @return DoctrineModelGenerator $connection
		 */
		public static function getDoctrineModelGeneratorFactory ()
		{
			if(self::$doctrineModelGenerator == null)
			{
				require_once (dirname(__FILE__)."/../doctrine/DoctrineModelGenerator.class.php");
				self::$doctrineModelGenerator = new DoctrineModelGenerator();
			}
			
			return self::$doctrineModelGenerator;
		}
		
		/**
		 * Returns an instance of PageAccessControl object. If instance
		 * is null create a new instance.
		 * 
		 * @return PageAccessControl $page
		 */
		public static function getPageAccessControlFactory ()
		{
			if(self::$pageAccessControl == null)
			{
				require_once (dirname(__FILE__)."/../controller/PageAccessControl.class.php");
				self::$pageAccessControl = new PageAccessControl();
			}
			
			return self::$pageAccessControl;
		}
		
		/**
		 * Returns an instance of Debug object. If instance
		 * is null create a new instance.
		 * 
		 * @return Debug $page
		 */
		public static function getDebugFactory ()
		{
			if(self::$debug == null)
			{
				require_once (dirname(__FILE__)."/../debug/Debug.class.php");
				self::$debug = new Debug();
			}
			
			return self::$debug;
		}
		
		/**
		 * Returns an instance of CapabilityManager object. If instance
		 * is null create a new instance.
		 * 
		 * @return CapabilityManager $capabilityManager
		 */
		public static function getCapabilityManagerFactory ()
		{
			if(self::$capabilityManager == null)
			{
				require_once (dirname(__FILE__)."/../controller/CapabilityManager.class.php");
				self::$capabilityManager = new CapabilityManager();
			}
			
			return self::$capabilityManager;
		}
		
		/**
		 * Returns an instance of HTMLComponent object. If instance
		 * is null create a new instance.
		 * 
		 * @return HTMLComponent $htmlComponent
		 */
		public static function getHTMLComponentFactory ()
		{
			if(self::$htmlComponent == null)
			{
				require_once (dirname(__FILE__)."/../html/HTMLComponent.class.php");
				self::$htmlComponent = new HTMLComponent();
			}
			
			return self::$htmlComponent;
		}
	}
?>